using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace AccessLayer
{
	public class fact_costs_revenuesDAO
{
		public static List<fact_costs_revenuesBO> GetAll()
		{
			return CBO.FillCollection<fact_costs_revenuesBO>(DataProvider.getInstance().getAll(TableName.fact_costs_revenues, PagingHelper.CreateOrder(new OrderObject(fact_costs_revenuesTable.cost_code, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<fact_costs_revenuesBO> GetAllC()
		{
			List<fact_costs_revenuesBO> list = new List<fact_costs_revenuesBO>();
			if(DataCache.GetCache(CacheName.fact_costs_revenues) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.fact_costs_revenues) != null)
					{
						list = (List<fact_costs_revenuesBO>)DataCache.GetCache(CacheName.fact_costs_revenues);
					}
					else
					{
			list = CBO.FillCollection<fact_costs_revenuesBO>(DataProvider.getInstance().getAll(TableName.fact_costs_revenues, PagingHelper.CreateOrder(new OrderObject(fact_costs_revenuesTable.cost_code, SortOrder.Desc))));
						DataCache.SetCache(CacheName.fact_costs_revenues, list);
					}
				}
			}
			else
			{
					list = (List<fact_costs_revenuesBO>)DataCache.GetCache(CacheName.fact_costs_revenues);
			}
		return list;
		}
		public static int InsertUpdateDelete(fact_costs_revenuesBO fact_costs_revenues, ProviderAction action)
		{
            ConnInfo.Db = "VNPT_Bsc";
            int rs = DataProvider.getInstance().InsertUpdateDelete(action, 
                StoreProcedureName.InsertUpdateDelete_fact_costs_revenues, 
                "@" + fact_costs_revenuesTable.cost_code, fact_costs_revenues.branch_code, fact_costs_revenues.cost_code, fact_costs_revenues.timekey, fact_costs_revenues.cost, fact_costs_revenues.unit_code, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.fact_costs_revenues);
			}
			return rs;
		}
        public static List<fact_costs_revenuesBO> GetByTimeKey(int key)
        {
            return CBO.FillCollection<fact_costs_revenuesBO>(
                DataProvider.getInstance().ExecuteReader(StoreProcedureName.spGetCostByKey,null,null,key,null));
        }
		
	}
}